home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / dacm.zip / CNV / UNIT3.PAS < prev   
Pascal/Delphi Source File  |  1995-11-17  |  5KB  |  192 lines

  1. unit Unit3;
  2.  
  3. interface
  4.  
  5. uses
  6.     SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.     Forms, Dialogs, StdCtrls, Mask, DBCtrls, DB, DBTables, DACMgr;
  8.  
  9. type
  10.     TForm3 = class(TForm)
  11.         OldTable: TTable;
  12.         Button1: TButton;
  13.     DACManager1: TDACManager;
  14.     SecurityObject1: TSecurityObject;
  15.         procedure Button1Click(Sender: TObject);
  16.     private
  17.         { Private declarations }
  18.     public
  19.         { Public declarations }
  20.     end;
  21.  
  22. var
  23.     Form3: TForm3;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28. {*********encrypt string procedure*********}
  29. function OldEncryptStr(lpTarget:string):string;
  30. var
  31. bit,bit2:byte;
  32. i,x:integer;
  33. lpEncrypt:char;
  34. begin
  35. x:=length(lpTarget);
  36. bit:=x;
  37. bit2:=bit XOR (bit + 1);
  38.  
  39.         for i:=1 to x do
  40.         begin
  41.                  lpEncrypt := lpTarget[i];
  42.                  lpEncrypt:=chr(ord(lpEncrypt) XOR bit);
  43.                  lpEncrypt:=chr(ord(lpEncrypt) XOR bit2);
  44.         inc(bit2);
  45.         dec(bit);
  46.         lpTarget[i] :=lpEncrypt;
  47.         end;
  48.  
  49.         result:=lpTarget;
  50. end;{OldEncryptStr}
  51. {This proc will convert an old table to a new table.
  52. Each Old record is read in and decrypted - As the PIN could be of variable
  53. length (if you altered our system!!) we deduct the OldName from the OldSID
  54. (which is supposed to be PIN+Name) to leave us (hopefully) with the PIN.
  55. At each record we add the old OList to a stringlist so we can convert this
  56. list to the new format later.
  57. A new record is created and we add to another list to allow us to match an
  58. old record to a new record (the oldOID is a string, the newOID is a longint)
  59. After completing part one, we have a new table with a record for each old
  60. record BUT it has no permissions.
  61.  
  62. So stage 2, we go to the stringlist containing the OldOlist (SOL) and
  63. process these one by one.
  64. OK so we get a string, we must parse this to get an individual group..
  65. the parsing is diferent for User and Object recs. Having got a group we
  66. look it up in MatchList to find its corresponding new GroupOID and then
  67. add this onto a new list that we are building.
  68. When we have parsed all the string for this loop we wrrite this new list
  69. into the security table.
  70.  
  71. A word on Permissions-The old and new Permissions are not really compatible
  72. even more so under the new scheme you can make permissions anything you want
  73. but we have tried our best
  74. Old - ---> Input  Modify Delete         Exceute
  75. New - Read Insert Modify Delete Approve Run
  76. So what we have done is to say
  77. 1. If you have any permissions we will bump them up one as we now have
  78. a new starting permission of Read
  79. 2. If you have any permissions for the object we will add in Read
  80. 3. If you have Execute permissions we will translate this to
  81. Approve and Run under the new system
  82.  
  83. IF YOU WANT TO DO IT DIFFERENT LOOK AT THE CODE BELOW and see where we
  84. manipulate the permissions.
  85.  
  86. WE REQUIRE EXCLUSIVE ACCESS TO THE NEW TABLE!!
  87. }
  88. procedure TForm3.Button1Click(Sender: TObject);
  89. var
  90. OldSID,OldOID,OldName,OldType,OldPIN,OldOList:string;
  91. OID:longint;
  92. SOL,MatchList:TStringList;
  93. x,xcnt:integer;
  94. AOID,AGroup:string;
  95. TmpBGroupP:byte;
  96. TmpAGroupP:string;
  97. GroupP:TPermissions;
  98. NewType:integer;
  99. P:pointer;
  100. Z:longint;
  101. FL:TList;
  102. begin
  103. Button1.Caption:='Starting';
  104. with DACM do EmptyTable;
  105. SOL:=TStringList.Create;
  106. MatchList:=TStringList.Create;
  107. FL:=TList.Create;
  108. with OldTable do
  109.     begin
  110.         xcnt:=0;
  111.         first;
  112.         while not EOF do
  113.         begin
  114.             OldSID:=OldEncryptStr(FieldByName('SID').AsString);
  115.             OldOID:=FieldByName('OID').AsString;
  116.             OldName:=OldEncryptStr(FieldByName('Name').AsString);
  117.             OldType:=FieldByName('Type').AsString;
  118.             OldOlist:=OldEncryptStr(FieldByName('OList').AsString);
  119.  
  120.             {build list of OLists}
  121.             SOL.Add(OldOlist);
  122.  
  123.             if OldType='U' then begin
  124.                 OldPIN:=copy(OldSID,0,length(OldSID)-length(OldName));
  125.                 Security.AppendUser(OldPIN,OldName,OID);
  126.                 MatchList.AddObject(OldOID,pointer(OID));{build lsit to match old/new}
  127.             end
  128.             else if OldType='G' then begin
  129.                 Security.AppendGroup(OldName,OID);
  130.                 MatchList.AddObject(OldOID,pointer(OID));
  131.             end
  132.             else if OldType='O' then begin
  133.                 Security.AppendObject(OldName,OldSID,OID);
  134.                 MatchList.AddObject(OldOID,pointer(OID));
  135.             end;
  136.  
  137.         Button1.Caption:='Processed Record '+inttostr(xcnt);
  138.     inc(xcnt);
  139.         next;
  140.         end;
  141.  
  142.         Button1.Caption:='Stage2';
  143.  
  144.         {with the items in SOL}
  145.         for x:=0 to SOL.Count-1 do
  146.         begin
  147.             FL.Clear;
  148.             TmpBGroupP:=0;
  149.  
  150.             {Get a list from SOL}
  151.             OldOlist:=SOL[x];
  152.  
  153.             {Find the new rec for this one}
  154.             P:= MatchList.Objects[x];
  155.             DACM.LocateOID(longint(P));
  156.             NewType:=DACM.FieldByName('Type').AsInteger;
  157.  
  158.             while Length(OldOlist)>0 do
  159.             begin
  160.                 AOID:=Copy(OldOlist,1,5);
  161.                 if NewType=3 then
  162.                 begin
  163.                     TmpAGroupP:=Copy(OldOlist,6,1);
  164.                     TmpBGroupP:=ord(TmpAGroupP[1])-32;
  165.                     TmpBGroupP:=TmpBGroupP shl 1 ;
  166.                     GroupP:=TPermissions(TmpBGroupP);
  167.                     system.delete(OldOlist,1,7);
  168.                     {Manipulate Permissions}
  169.                     if GroupP<>[] then include(GroupP,0);
  170.                     if (5 in GroupP) then Include(GroupP,4);
  171.                 end
  172.                 else
  173.                     system.delete(OldOlist,1,6);
  174.  
  175.                 if MatchList.IndexOf(AOID) <> -1 then
  176.                 begin
  177.                     P:=MatchList.Objects[MatchList.IndexOf(AOID)];
  178.                     Z:=longint(P);
  179.                     TOIDRec(Z).Permissions:=GroupP;
  180.                     FL.Add(pointer(Z));
  181.                 end;
  182.             end;
  183.             P:= MatchList.Objects[x];
  184.             {only write it if we can find the correct record}
  185.             if DACM.LocateOID(longint(P)) then DACM.WriteToOList(FL);
  186.         end;
  187.     end;
  188.     Button1.Caption:='Finished';
  189. end;
  190.  
  191. end.
  192.